package easy;

/**
 * 
 * Given nums = [2, 7, 11, 15], target = 9, Because nums[0] + nums[1] = 2 + 7 =
 * 9, return [0, 1].
 * 
 * @author MacBook
 *
 */
public class TwoSum {
	public static void main(String[] args) {
		int[] nums = { 2, 7, 11, 15 };
		int target = 9;
		int[] result = new TwoSum().twoSum(nums, target);
		System.out.println(result[0] + " " + result[1]);

	}

	public int[] twoSum(int[] nums, int target) {
		int i, j = 0;
		int[] result = new int[2];
		for (i = 0; i < nums.length; i++)
		{
				for (j = 0; j < i; j++) {
					if ((nums[i] + nums[j]) == target)
						break;
				}
				if(i != j)
					break;
		}
		result[0] = j;
		result[1] = i;
		return result;
	}
}
